<?php
$MenuList = Yii::app()->params['menu'];
?>
<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <title><?php echo empty($title) ? "" : $title; ?></title>
    <link rel="stylesheet" type="text/css" href="static/admin/lib/bootstrap/css/bootstrap.css">
    <link rel="stylesheet" href="static/admin/lib/font-awesome/css/font-awesome.css">
    <link rel="stylesheet" href="static/admin/lib/bootstrapvalidator/css/bootstrapValidator.css">
    <link rel="stylesheet" href="static/admin/lib/bootstrap-dialog/css/bootstrap-dialog.css">
    <script src="static/admin/lib/jquery-1.11.1.min.js" type="text/javascript"></script>
    <link rel="stylesheet" type="text/css" href="static/admin/stylesheets/theme.css">
    <link rel="stylesheet" type="text/css" href="static/admin/stylesheets/premium.css">
    <link rel="stylesheet" type="text/css" href="static/admin/stylesheets/other.css">
</head>
<body class="theme-blue">

<div class="navbar navbar-default" role="navigation" id="navbar">
    <div class="navbar-header">
        <img src="static/admin/images/white_logo.png" style="height: 40px;margin-top: 5px;"/>
    </div>
    <div class="navbar-collapse collapse navbar-right" style="height: 1px;">
        <ul id="main-menu" class="nav navbar-nav navbar-right">
            <li class="dropdown hidden-xs">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                    <span class="glyphicon glyphicon-user padding-right-small"
                          style="position:relative;top: 3px;"></span><?php echo Yii::app()->session ['user']['loginname']; ?>
                    <i class="fa fa-caret-down"></i>
                </a>
                <ul class="dropdown-menu user-tools">
                    <li class="dropdown-header">用户设置</li>
                    <li><a class="t" href="index.php?r=admin/admin/config">个人设置</a></li>
                    <li><a class="t" href="index.php?r=admin/admin/showchangepwd">修改密码</a></li>
                    <li><a href="index.php?r=admin/default/logout"><i class="icon-off red"></i>退出</a></li>
                    <li class="divider"></li>
                    <li class="dropdown-header">缓存管理</li>
                    <li><a href="javascript:clearAll();">刷新全站缓存</a></li>
                </ul>
            </li>
        </ul>
    </div>
    <form class="navbar-form navbar-right">
        <select class="form-control" name="mgrlang" onchange="changeMgrLang()">
            <?php
            foreach ($this->data['langs'] as $l) {
                if ($this->mgrlang == $l['lang']) {
                    ?>
                    <option value="<?php echo $l['lang']; ?>" selected="selected"><?php echo $l['name']; ?></option>
                    <?php
                } else {
                    ?>
                    <option value="<?php echo $l['lang']; ?>"><?php echo $l['name']; ?></option>
                    <?php
                }
            }
            ?>
        </select>
    </form>
</div>

<div class="sidebar-nav" style="height: 100%;overflow-y: auto;">
    <ul>
        <?php
        $seq = 1;
        $first = true;
        foreach ($MenuList as $m) {
            ?>
            <li>
                <a data-target=".dashboard-menu-<?php echo $seq; ?>" class="nav-header"
                   data-toggle="collapse"> <?php echo $m['name']; ?><i class="fa fa-collapse"></i></a></li>
            <?php
            if (sizeof($m['child']) > 0) {
                if ($first == true) {
                    echo '<li><ul id="dashboard-menu-' . $seq . '" class="dashboard-menu-' . $seq . ' dashboard-menu nav nav-list collapse in">';
                    $first = false;
                } else {
                    echo '<li><ul id="dashboard-menu-' . $seq . '" class="dashboard-menu-' . $seq . ' dashboard-menu nav nav-list collapse ">';
                }
                foreach ($m['child'] as $i) {
                    ?>
                    <li><a href="javascript:loadContent('<?php echo $i['url']; ?>')"><span
                                class="fa fa-caret-right"></span> <?php echo $i['name']; ?></a></li>
                    <?php
                }
                echo '</ul></li>';
            }
            $seq++;
        }
        ?>
    </ul>
    <div style="height: 90px;">&nbsp;&nbsp;</div>
</div>

<div class="content">
    <div id="div_container">
        <?php echo $content; ?>
    </div>
    <div style="height: 50px;">&nbsp;&nbsp;</div>
</div>
<script src="static/admin/lib/bootstrap/js/bootstrap.js"></script>
<script src="static/admin/lib/bootstrapvalidator/js/bootstrapValidator.min.js" type="text/javascript"></script>
<script src="static/admin/lib/jquery.form.min.js" type="text/javascript"></script>
<script src="static/admin/lib/bootstrap-growl/jquery.bootstrap-growl.js"></script>
<script src="static/admin/lib/bootstrap-dialog/js/bootstrap-dialog.min.js"></script>
<script src="static/admin/lib/global.js" type="text/javascript"></script>
<script type="text/javascript">
    $(function () {
        $(".content").height($(window).height() - $("#navbar").height());
        initHref();
    });
    function changeMgrLang() {
        var lang = $("select[name=mgrlang]").val();
        $.get('index.php?r=admin/console/mgrlang&lang=' + lang, null, function (result) {
            if (result.type == true) {
                window.location.reload();
            }
        }, 'json');
    }
    function loadContent(url) {
        $("#div_container").load(url);
    }
    function initHref() {
        $(".user-tools .t").on('click',function (event) {
            event.preventDefault();
            var href = $(this).attr("href");
            loadContent(href);
        });
    }
</script>
</body>
</html>